﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AllegroIWI.Comparers
{
	public class SamePictureComparer : Comparer<SearchResult>
	{
		public override int Compare(SearchResult x, SearchResult y)
		{
			if (x != null && x.Image != null && x.Image.Histogram != null &&
				y != null && x.Image != null && x.Image.Histogram != null)
			{
				int test;
				Histogram h1, h2;
				h1 = x.Image.Histogram;
				h2 = y.Image.Histogram;
				test = h1.Total.CompareTo(h2.Total);
				if (test != 0)
					return test;
				test = h1.rTotal.CompareTo(h2.rTotal);
				if (test != 0)
					return test;
				test = h1.gTotal.CompareTo(h2.gTotal);
				if (test != 0)
					return test;
				test = h1.bTotal.CompareTo(h2.bTotal);
				return test;
			}
			else
				return -1;
		}

	}
}
